extends Node2D

@export var fireball_scene: PackedScene = preload("res://scenes/vfx/fire_ball(火球)/fireball.tscn")

func _ready() -> void:
	# 创建一个简单的测试环境
	_create_test_environment()

func _input(event: InputEvent) -> void:
	if event is InputEventMouseButton:
		if event.button_index == MOUSE_BUTTON_LEFT and event.pressed:
			_spawn_fireball(event.position)

func _spawn_fireball(target_position: Vector2) -> void:
	var fireball = fireball_scene.instantiate() as Fireball
	add_child(fireball)
	
	# 从屏幕中心发射到鼠标位置
	var start_position = Vector2(640, 360)  # 屏幕中心
	var direction = target_position - start_position
	
	fireball.init(start_position, direction)
	print("发射火球！目标位置: ", target_position)

func _create_test_environment() -> void:
	# 创建一些测试用的墙壁或目标
	for i in range(3):
		var wall = StaticBody2D.new()
		var collision = CollisionShape2D.new()
		var shape = RectangleShape2D.new()
		shape.size = Vector2(50, 200)
		collision.shape = shape
		wall.add_child(collision)
		wall.position = Vector2(200 + i * 200, 300)
		add_child(wall)
		
		# 添加视觉表示
		var sprite = ColorRect.new()
		sprite.size = Vector2(50, 200)
		sprite.color = Color.GRAY
		wall.add_child(sprite) 
